import java.util.Scanner;

public class Demo {
    // 给定一个整型数组, 找到其中的最大元素 (找最小元素同理)
    public static int max (int[] array) {
        int max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
        return max;
    }
    public static void main(String[] args) {
        int[] arary = {1,2,3,4,5};
        System.out.println(max(arary));
    }
    // 返回一个新的数组
    public static void printf (int[] output) {
        for (int i = 0; i < output.length; i++) {
            System.out.println(output[i]);
        }
    }
    public static int[] transform (int[] array) {
        for (int i = 0; i < array.length; i++) {
            array [i] *= 2;
        }
        return array;
    }
    public static void main10(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] outpot = transform(array);
        printf(outpot);
    }
    // 使用foreach遍历数组
    // for-each 是 for 循环的另外一种使用方式. 能够更方便的完成对数组的遍历. 可以避免循环条件和更新语句写错.
    public static void main9(String[] args) {
        int [] araray = {1,2,3,4};
        for (int x : araray) {
            System.out.println(x);
        }

    }
    // 写一个递归方法，输入一个非负整数，返回组成它的数字之和.
    public static int sumnum (int n) {
        if (n < 10) {
            return n;
        }else {
            return sumnum(n/10) + n % 10;
        }
    }
    public static void main7(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(sumnum(n));
    }
    // 实现代码: 求斐波那契数列的第 N 项
    public static int fibo (int n) {
        if (n == 1 || n == 2) {
            return n;
        }
        int a = 0;
        int b = 1;
        int c = 0;
        for (int i = 3; i <= n; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return  c;
    }
    public static void main6(String[] args) {
        Scanner scanner =new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fibo(n));
    }
    //  实现代码: 青蛙跳台阶问题(提示, 使用递归)
    //一只青蛙一次可以跳上 1 级台阶，也可以跳上2 级。求该青蛙跳上一个n 级的台阶总共有多少种跳法
    public static int frogJump (int n) {
        if (n == 1 || n == 2) {
            return n;
        }else {
            return frogJump(n -1) + frogJump(n - 2);
        }
    }
    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(frogJump(n));
    }
    //  用递归计算1！+2！+3！+4！+5!
    public static int factsum (int i) {
        int sum = 0;
        for (int j = 1; j <= i ; j++) {
            sum += fact(j);
        }
        return sum;
    }
    public static void main4(String[] args) {
        int i = 5;
        System.out.println(factsum(i));
    }
    //  用递归计算5的阶乘
    public static int fact (int n) {
        if (n == 1) {
            return 1;
        }else {
            return fact(n - 1) * n;
        }
    }
    public static void main3(String[] args) {
        int n = 5;
        System.out.println(fact(n));
    }
    public static int sum (int n) {
        if (n == 1) {
            return 1;
        }else {
            return sum(n - 1) + n;
        }
    }
    // 用递归计算1+2+3+4+5
    public static void main2(String[] args) {
        int n = 5;
        System.out.println(sum(n));
    }
    // 用递归正序打印12345
    public static  void print (int n) {
        if (n < 10) {
            System.out.println(n);
        }else {
            print(n / 10);
            System.out.println(n % 10);
        }

    }
    public static void main1(String[] args) {
        int n =12345;
        print(n);
    }
}
